#include <memory>

#include "InetAddr.hpp"
#include "Log.hpp"
#include "UdpServer.hpp"
#include "User.hpp"

// 【./udp_Client  sever_port】
int main(int argc, char *argv[])
{
    // 1.格式：
    if (argc != 2)
    {
        std::cerr << "Usage: " << "sever_ip sever_port" << std::endl;
        Die(1);
    }
    // std::string ip = argv[1];
    uint16_t port = std::stoi(argv[1]);

    ENABLE_CONSOLE();

    // 用户管理模块
    std::shared_ptr<UserManger> um = std::make_shared<UserManger>();
    // 网络模块
    std::unique_ptr<UdpServer> svr_ptr = std::make_unique<UdpServer>(port);

    svr_ptr->RegisterService([&um](InetAddr &id) {um->AddUser(id); },
                             [&um](int sockfd, const std::string &message) {um->Router(sockfd, message); },
                             [&um](InetAddr &id) {um->DelUser(id); }
                            );

    svr_ptr->InitS();

    svr_ptr->Start();

    return 0;
}